/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package spring4.model;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import spring4.context.ValiadTwID;

@Entity
@Table(name = "user")
public class User implements Serializable {

    private static final long serialVersionUID = 1;
    @Id
    @Column(name = "user_key", nullable = true)
    private Integer userKey;
    @Column(name = "tw_id")
    @ValiadTwID
    private String twid;
    @Column(name = "user_name")
    @NotNull(message = "{NotNull}")
    @Size(min = 1, message = "{NotEmpty}")
    private String name;

    public Integer getUserKey() {
        return userKey;
    }

    public void setUserKey(Integer userKey) {
        this.userKey = userKey;
    }

    public String getTwid() {
        return twid;
    }

    public void setTwid(String twid) {
        this.twid = twid==null?null:twid.toUpperCase();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 79 * hash + (this.userKey != null ? this.userKey.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final User other = (User) obj;
        if (this.userKey != other.userKey && (this.userKey == null || !this.userKey.equals(other.userKey))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return String.format("[%s]%s", userKey == null ? twid : userKey.toString()+twid, name);
    }
}